package org.rsbot.gui;

import java.awt.Desktop;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.rsbot.util.GlobalConfiguration.Paths;

public class SplashAd extends JDialog
  implements MouseListener
{
  private static final long serialVersionUID = 1L;
  private static final String IMG_TYPE = "png";

  public SplashAd(JFrame paramJFrame)
  {
    super(paramJFrame);

    File localFile = new File(GlobalConfiguration.Paths.getCacheDirectory(), "advert.png");

    if ((localFile.exists()) && (localFile.lastModified() < new Date().getTime() - 86400000L)) {
      try {
        localFile.delete();
      }
      catch (Exception localException1)
      {
      }
    }
    if (!localFile.exists())
      try {
        BufferedImage localBufferedImage1 = ImageIO.read(new URL("http://links.powerbot.org/gold4rs-img"));
        ImageIO.write(localBufferedImage1, "png", localFile);
      }
      catch (Exception localException2)
      {
      }
    try {
      setDefaultCloseOperation(0);
      setUndecorated(true);
      setTitle("Advertisement");
      BufferedImage localBufferedImage2 = ImageIO.read(localFile);
      setSize(localBufferedImage2.getWidth(), localBufferedImage2.getHeight());

      JLabel localJLabel = new JLabel();
      localJLabel.setIcon(new ImageIcon(localBufferedImage2));
      add(localJLabel);

      addMouseListener(this);
      setLocationRelativeTo(getOwner());
      setVisible(true);

      Timer localTimer = new Timer();
      localTimer.schedule(new TimerTask()
      {
        public void run()
        {
          SplashAd.this.dispose();
        }
      }
      , 5000L);
    }
    catch (IOException localIOException)
    {
    }
  }

  public void mouseClicked(MouseEvent paramMouseEvent)
  {
    if (Desktop.isDesktopSupported()) {
      try {
        Desktop.getDesktop().browse(new URL("http://links.powerbot.org/gold4rs").toURI());
      }
      catch (Exception localException)
      {
      }
    }
    dispose();
  }

  public void mousePressed(MouseEvent paramMouseEvent)
  {
  }

  public void mouseReleased(MouseEvent paramMouseEvent)
  {
  }

  public void mouseEntered(MouseEvent paramMouseEvent)
  {
  }

  public void mouseExited(MouseEvent paramMouseEvent)
  {
  }
}